package com.lc.cehui.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.google.android.material.imageview.ShapeableImageView;
import com.lc.cehui.R;
import com.lc.cehui.http.glide.GlideApp;
import com.lc.cehui.http.response.CollectListOtherBean;
import com.lc.cehui.ui.activity.EnterpriseListActivity;
import com.lc.cehui.ui.activity.PersonnelListActivity;
import com.lc.cehui.ui.activity.home.ParticularsActivity;
import com.lc.cehui.ui.activity.home.ParticularsDetailsActivity;
import com.lc.cehui.ui.activity.home.ResumeDetailsActivity;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class CollectionOtherAdapter extends RecyclerView.Adapter{
    /*
    type=1 企业发布的招聘信息
type=2 收藏简历列表
type=3 校企合作
type=4 技能培训
type=5 企业资讯
type=6 项目对接
type=7 收藏企业

     */

    public static final int TYPE_ONE = 1;
    public static final int TYPE_TWO = 2;
    public static final int TYPE_THREE = 3;
    public static final int TYPE_FOUR = 4;
    public static final int TYPE_FIVE = 5;
    public static final int TYPE_SIX= 6;
    public static final int TYPE_SEVEN = 7;
    private Context context;

    private List<CollectListOtherBean.DataBean.ListBean> datas;

    public CollectionOtherAdapter(Context context, List<CollectListOtherBean.DataBean.ListBean> datas){
        this.context = context;
        this.datas = datas;

    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        if (viewType == TYPE_ONE){

            view = View.inflate(context, R.layout.item_gongsizhiwei, null);
            CollectionOtherAdapter.ItemOneViewHolder holder = new CollectionOtherAdapter.ItemOneViewHolder(view);

            holder.tv_name = view.findViewById(R.id.tv_name);
            holder.tv_salary = view.findViewById(R.id.tv_salary);
            holder.tv_tag = view.findViewById(R.id.tv_tag);
            holder.recyclerView2 = view.findViewById(R.id.recyclerView2);
            holder.ll_type = view.findViewById(R.id.ll_type);
            return  holder;
        }else if (viewType == TYPE_TWO){

            view = View.inflate(context, R.layout.adapter_personnellist,null);
            CollectionOtherAdapter.ItemTwoViewHolder holder = new CollectionOtherAdapter.ItemTwoViewHolder(view);
            holder.tv_title = view.findViewById(R.id.tv_title);
            holder.tv_body = view.findViewById(R.id.tv_body);
            holder.im_logo = view.findViewById(R.id.im_logo);
            holder.tv_count = view.findViewById(R.id.tv_count);
            holder.tv_work = view.findViewById(R.id.tv_work);
            holder.ll_type = view.findViewById(R.id.ll_type);

            return  holder;

        }else if (viewType == TYPE_THREE){
            view = View.inflate(context, R.layout.item_ziyuangongxiang, null);

            CollectionOtherAdapter.ItemTreeViewHolder holder = new CollectionOtherAdapter.ItemTreeViewHolder(view);

            holder.titile = view.findViewById(R.id.tv_title);
            holder.tv_name = view.findViewById(R.id.tv_name);
            holder.img = view.findViewById(R.id.img);
            holder.ll_type = view.findViewById(R.id.ll_type);
            return  holder;
        }else if (viewType == TYPE_SEVEN){
            view = View.inflate(context, R.layout.adapter_enterlist, null);

            CollectionOtherAdapter.ItemSeveniewHolder holder = new CollectionOtherAdapter.ItemSeveniewHolder(view);

            holder.tv_title = view.findViewById(R.id.tv_title);
            holder.tv_body = view.findViewById(R.id.tv_body);
            holder.im_logo = view.findViewById(R.id.im_logo);
            holder.tv_count = view.findViewById(R.id.tv_count);
            holder.tv_work = view.findViewById(R.id.tv_work);
            holder.ll_type = view.findViewById(R.id.ll_type);
            return  holder;
        }else {
            view = View.inflate(context, R.layout.item_ziyuangongxiang, null);

            CollectionOtherAdapter.ItemTreeViewHolder holder = new CollectionOtherAdapter.ItemTreeViewHolder(view);

            holder.titile = view.findViewById(R.id.tv_title);
            holder.tv_name = view.findViewById(R.id.tv_name);
            holder.img = view.findViewById(R.id.img);
            holder.ll_type = view.findViewById(R.id.ll_type);
            return  holder;
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof CollectionOtherAdapter.ItemOneViewHolder){
            CollectionOtherAdapter.ItemOneViewHolder viewHolder= (CollectionOtherAdapter.ItemOneViewHolder) holder;
            BaseQuickAdapter<CollectListOtherBean.DataBean.ListBean.WelfareBean, BaseViewHolder> adapter=new BaseQuickAdapter<CollectListOtherBean.DataBean.ListBean.WelfareBean, BaseViewHolder>(R.layout.item_gongsifuli2,datas.get(position).getWelfare()) {
                @Override
                protected void convert(@NotNull BaseViewHolder holder, CollectListOtherBean.DataBean.ListBean.WelfareBean item) {
                    holder.setText(R.id.tv_name,item.getTitle());
                }
            };
            viewHolder.recyclerView2.setAdapter(adapter);
            viewHolder.tv_name.setText(datas.get(position).getTitle());
            viewHolder.tv_salary.setText(datas.get(position).getSalary());
            viewHolder.tv_tag.setText(datas.get(position).getWork_city()+ datas.get(position).getWork_district()+"  ｜  "+datas.get(position).getYears()+"  ｜  "+ datas.get(position).getEducation());
            viewHolder.ll_type.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivity(new Intent(context, ParticularsDetailsActivity.class).putExtra("company_id",datas.get(position).getStore_id()+"").putExtra("job_id",datas.get(position).getJob_id()+""));
                }
            });
        }else if (holder instanceof CollectionOtherAdapter.ItemTwoViewHolder){

            CollectionOtherAdapter.ItemTwoViewHolder viewHolder= (CollectionOtherAdapter.ItemTwoViewHolder) holder;
            viewHolder.tv_title.setText(datas.get(position).getTitle());
            viewHolder.tv_body.setText(datas.get(position).getWork_city()+"  ｜ "+datas.get(position).getYears()+"  ｜ "+datas.get(position).getEducation());
            viewHolder.tv_count.setText(datas.get(position).getSalary());
            viewHolder.tv_work.setText(datas.get(position).getName());
            GlideApp.with(context).load(datas.get(position).getPicurl())
                    .apply(new RequestOptions().placeholder(R.drawable.image11).error(R.drawable.image11)).into(((ImageView) viewHolder.im_logo));
            viewHolder.ll_type.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivity(new Intent(context, ResumeDetailsActivity.class).putExtra("id",datas.get(position).getJob_id()+""));

                }
            });


        }
        else if (holder instanceof CollectionOtherAdapter.ItemSeveniewHolder){
            CollectionOtherAdapter.ItemSeveniewHolder viewHolder= (CollectionOtherAdapter.ItemSeveniewHolder) holder;
            GlideApp.with(context).load(datas.get(position).getPicurl()).apply(new RequestOptions().placeholder(R.drawable.image11).error(R.drawable.image11)).into((ImageView) viewHolder.im_logo);
            viewHolder.tv_title.setText(datas.get(position).getName());
            viewHolder.tv_body.setText( datas.get(position).getIndustry()+"  ｜ "+datas.get(position).getNature());
            viewHolder.tv_work.setText(datas.get(position).getWork());
            viewHolder.tv_count.setText( "等"+datas.get(position).getCount()+"个职位");
            viewHolder.ll_type.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivity(new Intent(context, ParticularsActivity.class).putExtra("id",datas.get(position).getStore_id()+""));

                }
            });

        }
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }
    @Override
    public int getItemViewType(int position) {
        CollectListOtherBean.DataBean.ListBean bean = datas.get(position);
        if (bean.getType() == TYPE_ONE ){
            return TYPE_ONE;
        }else if (bean.getType() == TYPE_TWO){
            return TYPE_TWO;
        }else if (bean.getType() == TYPE_SEVEN){
            return TYPE_SEVEN;
        }else {
            return TYPE_THREE;
        }
    }
    public void setData(List<CollectListOtherBean.DataBean.ListBean> dataList) {
        datas=dataList;
        notifyDataSetChanged();
    }
    class ItemOneViewHolder extends RecyclerView.ViewHolder{
        TextView tv_tag;
        TextView tv_name;
        TextView tv_salary;
        RecyclerView recyclerView2;

        RelativeLayout ll_type;
        public ItemOneViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }


    class ItemTwoViewHolder extends RecyclerView.ViewHolder{
        TextView tv_title;
        TextView tv_body;
        TextView tv_work;
        TextView tv_count;
        ImageView im_logo;

        LinearLayout ll_type;

        public ItemTwoViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
    class ItemTreeViewHolder extends RecyclerView.ViewHolder{
        TextView titile;
        TextView tv_name;
        ShapeableImageView img;

        LinearLayout ll_type;
        public ItemTreeViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
    class ItemFourViewHolder extends RecyclerView.ViewHolder{
        TextView titile;
        TextView tv_name;
        ShapeableImageView img;

        LinearLayout ll_type;
        public ItemFourViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
    class ItemFiveViewHolder extends RecyclerView.ViewHolder{
        TextView titile;
        TextView tv_name;
        ShapeableImageView img;

        LinearLayout ll_type;
        public ItemFiveViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
    class ItemSixViewHolder extends RecyclerView.ViewHolder{
        TextView titile;
        TextView tv_name;
        ShapeableImageView img;

        LinearLayout ll_type;
        public ItemSixViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
    class ItemSeveniewHolder extends RecyclerView.ViewHolder{
        TextView tv_title;
        TextView tv_body;
        TextView tv_work;
        TextView tv_count;
         ImageView im_logo;

        LinearLayout ll_type;
        public ItemSeveniewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
